package com.example.linktop.active;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class FirstActivity extends AppCompatActivity {

    private Button btn;
    private final int SECOND_TAG = 1; //标记下一个活动

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fitst_layout);

        btn = (Button) findViewById(R.id.btn1);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //跳转 second
                Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
                intent.putExtra("name", "你爸爸");

//                startActivity(intent);
                startActivityForResult(intent, SECOND_TAG);


            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()) {
            case R.id.add_item:

                Toast.makeText(getApplicationContext(),"点击添加", Toast.LENGTH_SHORT).show();

                break;


            case R.id.remove_item:
                Toast.makeText(getApplicationContext(),"点击删除", Toast.LENGTH_SHORT).show();
                break;
            default:
                break;

        }

        return true;
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        switch(requestCode) {
            case SECOND_TAG:
                if (resultCode == RESULT_OK) {

                    Log.w("onActivityResult",data.getStringExtra("back"));
                }

                break;

            default:
                break;



        }

    }



    @Override
    protected void onDestroy() {

        super.onDestroy();
    }
}
